cmake_minimum_required(VERSION 3.18)
project(unit_test)

set(test_libs PRIVATE GTest::gtest_main PRIVATE GTest::gmock PRIVATE spdlog::spdlog)

function(add_unit_test name)
    foreach (item ${ARGN})
        list(APPEND test_source_list ${CMAKE_CURRENT_SOURCE_DIR}/../src/simple/${item})
    endforeach ()

    add_executable(${name} ${name}.cc ${test_source_list})
    target_link_libraries(${name} ${test_libs})
    target_include_directories(${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src/simple/include)
    add_test(NAME ${name} COMMAND ${name})
endfunction()

add_unit_test(base_test)
add_unit_test(handler_base_test handler_base.cc session.cc reader_buf.cc writer_buf.cc)
add_unit_test(event_test event.cc handler_base.cc session.cc reader_buf.cc writer_buf.cc)
add_unit_test(reader_buf_test reader_buf.cc)
add_unit_test(writer_buf_test writer_buf.cc)
add_unit_test(session_test session.cc reader_buf.cc writer_buf.cc)
add_unit_test(socket_epoll_test socket_epoll.cc session.cc reader_buf.cc writer_buf.cc event.cc handler_base.cc)
